clear all;

load('prov.mat'); load('comm_loc.mat'); 
comm_loc=comm_loc(:,1:11);

prov=unique(prov_mkt);
num_prov=length(prov);
num_combination(1:num_prov)=1;
for i=1:num_prov
    mkt_index=find(prov_mkt==prov(i));
    num_mkt=length(mkt_index);
    num_86branch=sum(comm_loc(mkt_index,1));
    num_new_branch=sum(comm_loc(mkt_index,11))-num_86branch;
    new_branch_each_year(1:10)=0;
    num_mkt_no86branch=num_mkt-num_86branch;
    left_mkt=num_mkt_no86branch;
    for i_t=1:10
        num_branch_each_year(i_t)=sum(comm_loc(mkt_index,i_t+1)-comm_loc(mkt_index,i_t));
        num_combination(i)=num_combination(i)*nchoosek(left_mkt,num_branch_each_year(i_t));
        left_mkt=left_mkt-num_branch_each_year(i_t);
    end
end 


info=[prov,num_combination'];

info=sortrows(info,2);
